package com.pt25.service.sys.domain.config.ddo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.pt25.base.util.JsonUtil;
import com.pt25.base.util.PageUtil;
import com.pt25.service.sys.repository.mysql.po.ConfigValuePo;
import lombok.*;

import java.time.LocalDateTime;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(
        callSuper = true
)
public class ConfigValue extends PageUtil.PageBase {
    @JsonFormat(
            shape = JsonFormat.Shape.STRING
    )
    private Long id;

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long configDataId;

    private String valueKey;

    private Object valueContent;

    private String valueDescription;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    private Integer delFlag;

    public ConfigValuePo toConfigValuePo() {
        ConfigValuePo configValuePo = ConfigValuePo
                .builder()
                .configDataId(configDataId)
                .valueKey(valueKey)
                .valueContent(JsonUtil.toJson(valueContent))
                .valueDescription(valueDescription)
                .build();
        configValuePo.setId(id);
        return configValuePo;
    }

    public static ConfigValue toConfigValue(ConfigValuePo configValuePo) {
        return JsonUtil.toBean(JsonUtil.toJson(configValuePo), ConfigValue.class);
    }
}
